/*
 * OpenDialog.java
 *
 * Created on 17 de Dezembro de 2004, 16:43
 */

package ceirinhashls.gui;
import ceirinhashls.OpenDCHubList;
import ceirinhashls.util.Settings;
/**
 *
 * @author  botelhodaniel
 */
public class OpenDialog extends javax.swing.JDialog {
    private MainFrame mf;
    /** Creates new form OpenDialog */
    public OpenDialog(MainFrame mf) {
        super(mf, true);
        this.mf = mf;
        initComponents();
        doDefault();
    }
    private void doDefault(){
        jTextField1.setText(Settings.OPEN_HUBLIST);
    }
    private void setDefault(){
        Settings.OPEN_HUBLIST = jTextField1.getText().trim();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jTextField1.setColumns(40);
        jPanel1.add(jTextField1);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setText(StringDef.OK);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel2.add(jButton1);

        jButton2.setText(StringDef.CANCEL);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel2.add(jButton2);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        pack();
    }//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        doDefault();
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        OpenDCHubList.openFile(mf.getPublicHubList(), jTextField1.getText().trim());
        System.out.println("Size: "+mf.getPublicHubList().getSize());
        setDefault();
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    
}
